// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.Security;

public sealed partial class PrivilegeActions
{
	[JsonInclude, JsonPropertyName("actions")]
	public ICollection<string> Actions { get; set; }
	[JsonInclude, JsonPropertyName("application")]
	public string? Application { get; set; }
	[JsonInclude, JsonPropertyName("metadata")]
	public IDictionary<string, object>? Metadata { get; set; }
	[JsonInclude, JsonPropertyName("name")]
	public Elastic.Clients.Elasticsearch.Serverless.Name? Name { get; set; }
}

public sealed partial class PrivilegeActionsDescriptor : SerializableDescriptor<PrivilegeActionsDescriptor>
{
	internal PrivilegeActionsDescriptor(Action<PrivilegeActionsDescriptor> configure) => configure.Invoke(this);

	public PrivilegeActionsDescriptor() : base()
	{
	}

	private ICollection<string> ActionsValue { get; set; }
	private string? ApplicationValue { get; set; }
	private IDictionary<string, object>? MetadataValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Name? NameValue { get; set; }

	public PrivilegeActionsDescriptor Actions(ICollection<string> actions)
	{
		ActionsValue = actions;
		return Self;
	}

	public PrivilegeActionsDescriptor Application(string? application)
	{
		ApplicationValue = application;
		return Self;
	}

	public PrivilegeActionsDescriptor Metadata(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> selector)
	{
		MetadataValue = selector?.Invoke(new FluentDictionary<string, object>());
		return Self;
	}

	public PrivilegeActionsDescriptor Name(Elastic.Clients.Elasticsearch.Serverless.Name? name)
	{
		NameValue = name;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		writer.WritePropertyName("actions");
		JsonSerializer.Serialize(writer, ActionsValue, options);
		if (!string.IsNullOrEmpty(ApplicationValue))
		{
			writer.WritePropertyName("application");
			writer.WriteStringValue(ApplicationValue);
		}

		if (MetadataValue is not null)
		{
			writer.WritePropertyName("metadata");
			JsonSerializer.Serialize(writer, MetadataValue, options);
		}

		if (NameValue is not null)
		{
			writer.WritePropertyName("name");
			JsonSerializer.Serialize(writer, NameValue, options);
		}

		writer.WriteEndObject();
	}
}